# 递归再联系
# by Nasa 2022-4-6
# 计算阶乘
import math


def factorial(num):
    if num == 1:
        # print(1)
        return 1
    # print(num)
    return factorial(num - 1) * num


# 计算斐波那契数列的第num个数
def fibonacci(num):
    if num == 1 or num == 2:
        return 1
    return fibonacci(num - 1) + fibonacci(num - 2)


# 遍历多维数组
def traverse(arr):
    if type(arr) is not list:
        print(arr)
        return
    for i in arr:
        # print(i)
        traverse(i)


def fibonacci02(num):
    l = [1, 1]
    for i in range(num - 2):
        l.append(l[i] + l[i + 1])
        # print(l,i)
    return l[num - 1]


def is_prime(n):
    """素数判定"""
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True


def fenjie(num):
    if is_prime(num):
        print(num)
        return
    for i in range(2, num // 2 + 1):
        if is_prime(i) and num % i == 0:
            print(i)
            fenjie(num // i)
            break


if __name__ == '__main__':
    print(factorial(10))
    print(fibonacci02(12))
    print(fibonacci(12))
    my_list = [[[[[0]]]], 1, 2, [3, 4], [5, [6, 7], 8], 9]
    # my_list = [[[[[0]]]]]
    # traverse(my_list)
    print(is_prime(2))
    print('开方 ', math.sqrt(8))
    fenjie(3 * 2 * 11 * 13 * 17)
